﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Schedulr.Infrastructure;
using Schedulr.Models;

namespace Schedulr.Test
{
    [TestClass]
    public class SchedulrExtensionsTest
    {
        [TestMethod]
        public void ValueOr()
        {
            Assert.AreEqual<bool>(true, new bool?(true).ValueOr(false));
            Assert.AreEqual<bool>(false, new bool?(false).ValueOr(false));
            Assert.AreEqual<bool>(true, new bool?(true).ValueOr(true));
            Assert.AreEqual<bool>(false, new bool?(false).ValueOr(true));
            Assert.AreEqual<bool>(true, new bool?().ValueOr(true));
            Assert.AreEqual<bool>(false, new bool?().ValueOr(false));
        }

        [TestMethod]
        public void GetLowestBatch()
        {
            ICollection<Picture> pictures = null;
            var batch = pictures.GetLowestBatch();
            Assert.IsNotNull(batch);
            Assert.AreEqual<int>(0, batch.Count);

            pictures = new List<Picture>();
            batch = pictures.GetLowestBatch();
            Assert.IsNotNull(batch);
            Assert.AreEqual<int>(0, batch.Count);

            var pic3 = new Picture { BatchId = 3 };
            pictures.Add(pic3);
            batch = pictures.GetLowestBatch();
            Assert.IsNotNull(batch);
            Assert.AreEqual<int>(1, batch.Count);
            Assert.AreSame(pic3, batch[0]);

            var pic1a = new Picture { BatchId = 1 };
            pictures.Add(pic1a);
            batch = pictures.GetLowestBatch();
            Assert.IsNotNull(batch);
            Assert.AreEqual<int>(1, batch.Count);
            Assert.AreSame(pic1a, batch[0]);

            var pic1b = new Picture { BatchId = 1 };
            pictures.Add(pic1b);
            batch = pictures.GetLowestBatch();
            Assert.IsNotNull(batch);
            Assert.AreEqual<int>(2, batch.Count);
            Assert.AreSame(pic1a, batch[0]);
            Assert.AreSame(pic1b, batch[1]);
        }
    }
}